package testers;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class HelloWorldScreen extends MainScreen  {
	public HelloWorldScreen(){
		super();
		LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS
		 | LabelField.USE_ALL_WIDTH);
		setTitle(title);
		
		  FieldChangeListener bhandler = new FieldChangeListener()
          {
              public void fieldChanged(Field field, int context)
              {		
                  ButtonField buttonField = (ButtonField) field;
                  if (buttonField.getLabel() == "RED")
                  {
                      Background newback = BackgroundFactory.createSolidBackground(Color.RED);
                      getMainManager().setBackground(newback);
                      buttonField.setLabel("BLUE");
                         
                  }
                  else
                  {
                      Background newback = BackgroundFactory.createSolidBackground(Color.BLUE);
                      getMainManager().setBackground(newback);
                      buttonField.setLabel("RED");
                      addSomething();
                  }
              }
           };
           // Define button itself to use handler above, this one called RED
           ButtonField buttonField = new ButtonField("RED");     // Create RED button
           buttonField.setChangeListener(bhandler);               // Set up button handler defined above
         //  buttonField.setChangeListener(null);
           
           add(buttonField);  // Add the button to the screen.
           
	}
	public void addSomething()
	{
		this.add(new RichTextField( "bla"));
		 // request the content you wish to display
		 // this method call is typically called once
		// browserField.requestContent( "http://www.gmail.com" );
	}

}
